package com.rimi.dao.impl;

import com.rimi.bean.RoleBean;
import com.rimi.dao.RoleDao;
import com.rimi.util.JdbcUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl extends JdbcUtil implements RoleDao {

    private RoleBean parseResultToRole(ResultSet resultSet) throws SQLException {
        RoleBean roleBean=new RoleBean();
        roleBean.setRoleId(resultSet.getInt(1));
        roleBean.setRoleName(resultSet.getString(2));
        roleBean.setRoleStatus(resultSet.getInt(3));
        return roleBean;
    }

    @Override
    public List<RoleBean> selectRoleList() {
        ResultSet resultSet = executeQuerySql("select * from tb_role ");
        List<RoleBean> roleBeanList=new ArrayList<>();
        try {
            while (resultSet.next()){
                roleBeanList.add(parseResultToRole(resultSet));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeRes();
        }
        return roleBeanList;
    }


}
